#include <QKeyEvent>

#include "PressButtonDialog.h"
#include "ui_PressButtonDialog.h"

PressButtonDialog::PressButtonDialog(QWidget *parent) :
        QDialog(parent),
        m_ui(new Ui::PressButtonDialog)
{
    m_ui->setupUi(this);
}

PressButtonDialog::~PressButtonDialog()
{
    delete m_ui;
}

// Getters
QString PressButtonDialog::getKey(){
    return key;
}

void PressButtonDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void PressButtonDialog::keyPressEvent(QKeyEvent * event){

    switch(event->key()){

    case Qt::Key_Space:
        m_ui->labPress->setText("SPACE");
        break;

    case Qt::Key_Tab:
        m_ui->labPress->setText("TAB");
        break;

    case Qt::Key_Return:
        m_ui->labPress->setText("ENTER");
        break;

    case Qt::Key_Escape:
        m_ui->labPress->setText("ESCAPE");
        break;

    case Qt::Key_Pause:
        m_ui->labPress->setText("PAUSE");
        break;

    case Qt::Key_Backspace:
        m_ui->labPress->setText("BACKSPACE");
        break;

    case Qt::Key_Up:
        m_ui->labPress->setText("UPARROW");
        break;

    case Qt::Key_Down:
        m_ui->labPress->setText("DOWNARROW");
        break;

    case Qt::Key_Left:
        m_ui->labPress->setText("LEFTARROW");
        break;

    case Qt::Key_Right:
        m_ui->labPress->setText("RIGHTARROW");
        break;

    case Qt::Key_Alt:
        m_ui->labPress->setText("ALT");
        break;

    case Qt::Key_Control:
        m_ui->labPress->setText("CTRL");
        break;

    case Qt::Key_Shift:
        m_ui->labPress->setText("SHIFT");
        break;

    case Qt::Key_Insert:
        m_ui->labPress->setText("INS");
        break;

    case Qt::Key_Delete:
        m_ui->labPress->setText("DEL");
        break;

    case Qt::Key_PageDown:
        m_ui->labPress->setText("PGDN");
        break;

    case Qt::Key_PageUp:
        m_ui->labPress->setText("PGUP");
        break;

    case Qt::Key_Home:
        m_ui->labPress->setText("HOME");
        break;

    case Qt::Key_End:
        m_ui->labPress->setText("END");
        break;

    case Qt::Key_F1:
        m_ui->labPress->setText("F1");
        break;

    case Qt::Key_F2:
        m_ui->labPress->setText("F2");
        break;

    case Qt::Key_F3:
        m_ui->labPress->setText("F3");
        break;

    case Qt::Key_F4:
        m_ui->labPress->setText("F4");
        break;

    case Qt::Key_F5:
        m_ui->labPress->setText("F5");
        break;

    case Qt::Key_F6:
        m_ui->labPress->setText("F6");
        break;

    case Qt::Key_F7:
        m_ui->labPress->setText("F7");
        break;

    case Qt::Key_F8:
        m_ui->labPress->setText("F8");
        break;

    case Qt::Key_F9:
        m_ui->labPress->setText("F9");
        break;

    case Qt::Key_F10:
        m_ui->labPress->setText("F10");
        break;

    case Qt::Key_F11:
        m_ui->labPress->setText("F11");
        break;

    case Qt::Key_F12:
        m_ui->labPress->setText("F12");
        break;

    case Qt::Key_NumLock:
        m_ui->labPress->setText("KP_NUMLOCK");
        break;

    case Qt::Key_Semicolon:
        m_ui->labPress->setText("SEMICOLON");
        break;

    default:
        m_ui->labPress->setText(event->text());
        break;
    }
}



//******************* release *************************

void PressButtonDialog::keyReleaseEvent(QKeyEvent * event){

    switch(event->key()){

    case Qt::Key_Space:
        m_ui->labPress->setText("SPACE");
        break;

    case Qt::Key_Tab:
        m_ui->labPress->setText("TAB");
        break;

    case Qt::Key_Return:
        m_ui->labPress->setText("ENTER");
        break;

    case Qt::Key_Escape:
        m_ui->labPress->setText("ESCAPE");
        break;

    case Qt::Key_Pause:
        m_ui->labPress->setText("PAUSE");
        break;        

    case Qt::Key_Backspace:
        m_ui->labPress->setText("BACKSPACE");
        break;

    case Qt::Key_Up:
        m_ui->labPress->setText("UPARROW");
        break;

    case Qt::Key_Down:
        m_ui->labPress->setText("DOWNARROW");
        break;

    case Qt::Key_Left:
        m_ui->labPress->setText("LEFTARROW");
        break;

    case Qt::Key_Right:
        m_ui->labPress->setText("RIGHTARROW");
        break;

    case Qt::Key_Alt:
        m_ui->labPress->setText("ALT");
        break;

    case Qt::Key_Control:
        m_ui->labPress->setText("CTRL");
        break;

    case Qt::Key_Shift:
        m_ui->labPress->setText("SHIFT");
        break;

    case Qt::Key_Insert:
        m_ui->labPress->setText("INS");
        break;

    case Qt::Key_Delete:
        m_ui->labPress->setText("DEL");
        break;

    case Qt::Key_PageDown:
        m_ui->labPress->setText("PGDN");
        break;

    case Qt::Key_PageUp:
        m_ui->labPress->setText("PGUP");
        break;

    case Qt::Key_Home:
        m_ui->labPress->setText("HOME");
        break;

    case Qt::Key_End:
        m_ui->labPress->setText("END");
        break;       

    case Qt::Key_F1:
        m_ui->labPress->setText("F1");
        break;

    case Qt::Key_F2:
        m_ui->labPress->setText("F2");
        break;

    case Qt::Key_F3:
        m_ui->labPress->setText("F3");
        break;

    case Qt::Key_F4:
        m_ui->labPress->setText("F4");
        break;

    case Qt::Key_F5:
        m_ui->labPress->setText("F5");
        break;

    case Qt::Key_F6:
        m_ui->labPress->setText("F6");
        break;

    case Qt::Key_F7:
        m_ui->labPress->setText("F7");
        break;

    case Qt::Key_F8:
        m_ui->labPress->setText("F8");
        break;

    case Qt::Key_F9:
        m_ui->labPress->setText("F9");
        break;

    case Qt::Key_F10:
        m_ui->labPress->setText("F10");
        break;

    case Qt::Key_F11:
        m_ui->labPress->setText("F11");
        break;

    case Qt::Key_F12:
        m_ui->labPress->setText("F12");
        break;

    case Qt::Key_NumLock:
        m_ui->labPress->setText("KP_NUMLOCK");
        break;

    case Qt::Key_Semicolon:
        m_ui->labPress->setText("SEMICOLON");
        break;

    default:
        m_ui->labPress->setText(event->text());
        break;
    }

    key = m_ui->labPress->text();
    emit accepted();
    this->close();
}

